package com.sys.controller;

import com.sys.common.aop.Operation;
import com.sys.common.constant.Constant;
import com.sys.common.util.ResponseDateUtil;
import com.sys.common.util.ResultBuilder;
import com.sys.pojo.Log;
import com.sys.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ZJF
 * @since 2021-04-01
 */
@Api(tags = {"日志管理"})
@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService logService;

    @PostMapping("/queryLog")
    @RequiresPermissions("log:list")
    @ApiOperation("查看日志")
    public ResponseDateUtil pageLog(@RequestBody Log log) {
        return ResultBuilder.success(logService.findListByPage(log));
    }


    @DeleteMapping("/removeLog")
    @Operation("批量删除日志")
    @ApiOperation("批量删除日志")
    @RequiresPermissions("log:remove")
    public ResponseDateUtil removeLog(@RequestBody Log log) {
        boolean delete = logService.delete(log.getIds());
        if (delete) {
            return ResultBuilder.success(Constant.DELSUCCESS);
        } else {
            return ResultBuilder.errorInfo(Constant.DELFAILED);
        }
    }
}
